package com.bky.queue;

import com.bky.service.impl.QueryService;
import org.slf4j.Logger;

import java.util.Map;
import java.util.concurrent.BlockingQueue;

/**
 * Created by shipeilei on 2017/5/27.
 */
public class Consumer implements Runnable{
    private QueryService queryService;
    private BlockingQueue queue;
    private Logger LOGGER;

    public Consumer(BlockingQueue queue, QueryService queryService, Logger LOGGER) {
        this.queue = queue;
        this.queryService = queryService;
        this.LOGGER = LOGGER;
    }

    @Override
    public void run() {
        LOGGER.info("队列消费者，当前线程编号：{}, 线程名称：{}", Thread.currentThread().getId(), Thread.currentThread().getName());
        for (int i = 0; i < queue.size(); i++){
            try {
                Map map = (Map) queue.take();
                queryService.startUpdate(map);
            } catch (Exception e) {
                LOGGER.error("队列信息插入异常", e);
            }
        }
    }
}
